##package navigation

window.navigation = {}

( ->

##private

  $current_dojo_content = null
  $current_hall_content = null
  $dojo_nav = null
  $hall_nav = null
  $dojo_subnav = null
  $hall_subnav = null
  dojo_state = null
  dojo_sections = null
  dojo_headers = null

  setup_properties = ->
    $current_dojo_content = $('#vc')
    $current_hall_content = $('#hc')
    dojo_state = {'#v':'c','#g':'c','#a':'c'}
    dojo_sections = [$('#vc'), $('#vl'), $('#gc'), $('#gl'), $('#ac'), $('#al')]
    dojo_headers = [$('#vcn'), $('#grn'), $('#acn')]
    $dojo_nav = $('#djn')
    $hall_nav = $('#hzn')
    $dojo_subnav = $('#djsn')
    $hall_subnav = $('#hzsn')

  swap = (one, two) ->
    one.hide()
    two.show()

  set_topnav = (id) ->
    return unless id == '#djn' or id == '#hzn'
    if id == '#djn' && $hall_nav.hasClass("active")
      $hall_nav.removeClass("active")
      $dojo_nav.addClass("active")
      show_dojo()
    else if $dojo_nav.hasClass("active")
      $dojo_nav.removeClass("active")
      $hall_nav.addClass("active")
      show_hall()

  show_dojo = ->
    swap $current_hall_content, $current_dojo_content
    swap $hall_subnav, $dojo_subnav

  show_hall = ->
    swap $current_dojo_content, $current_hall_content
    swap $dojo_subnav, $hall_subnav

  change_dojo = (id, topnav) ->
    $elements = []
    if id.length == 2
      $elements.push $(id + dojo_state[id])
      $elements.push $(id + 'left')
      $elements.push $(id + 'right')
      console.log($elements)
    else if id.length == 3
      dojo_state[id.substr(0,2)] = id.charAt 2
      $elements.push $(id)
    $topnav = $(topnav)
    if not $topnav.hasClass("active")
      $.each dojo_headers, (i,s) ->
        s.removeClass "active"
      $topnav.addClass "active"
      $('.sidebar').hide()
      $.each dojo_sections, (i,s) ->
        s.hide()
      $.each $elements, (i,$e) ->
        $e.show()

##public

##initialize

  navigation.initialize = ->
    setup_properties()
    $dojo_nav.mouseup -> set_topnav '#djn'
    $hall_nav.mouseup -> set_topnav '#hzn'
    dojo_headers[0].mouseup -> change_dojo '#v', '#vcn'
    dojo_headers[1].mouseup -> change_dojo '#g', '#grn'
    dojo_headers[2].mouseup -> change_dojo '#a', '#acn'

##end

)()
